package com.activemq.jar.activemqjar.listener;

import org.springframework.jms.JmsException;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.TextMessage;

/**
 * @date 2020/10/8 17:11
 */
@Component
public class MsgConsumer {


    @JmsListener(destination = "queue-hello-web")
    public void receiveQueue(TextMessage textMessage) throws JMSException {
            System.out.println("接收到队列消息："+textMessage.getText());
    }


    /**
     * 用来监听topic，第二参数是自己实现的监听器
     * @param textMessage
     * @throws JMSException
     */
    @JmsListener(destination = "topic-hello-web",containerFactory = "jmsTopicContainerFactory")
    public void receiveTopic(TextMessage textMessage)throws JMSException {
        System.out.println("接收到主题消息：" + textMessage.getText());
    }


}
